package com.example.controller;

import com.alipay.api.AlipayApiException;
import com.example.common.annotation.OperLog;
import com.example.common.enums.LogType;
import com.example.common.utils.R;
import com.example.system.dto.PaymentDTO;
import com.example.system.entity.Patient;
import com.example.system.service.IPatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 王鹤蒲
 * @Date 2024 01 25
 */

@Api(tags = "患者信息API",description="提供患者信息相关的 REST API")
@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private IPatientService iPatientService;

    @OperLog(operation = "患者管理",type = LogType.ADD)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/save",method=RequestMethod.POST)
    @ResponseBody
    public R insert(@RequestBody Patient patient) {
     return iPatientService.insert(patient);
    }



    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/selectAll",method=RequestMethod.GET)
    @ResponseBody
    public R selectAll(@RequestParam int currentPage,@RequestParam int pageSize,@RequestParam(defaultValue = "") String patientName){
        return iPatientService.selectAll(currentPage,pageSize,patientName);
    }


    @OperLog(operation = "患者管理",type = LogType.DELETE)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/delete/{id}",method=RequestMethod.DELETE)
    @ResponseBody
    public R deleteById(@PathVariable("id")int id) {
     return iPatientService.deleteById(id);
    }


    @OperLog(operation = "患者管理",type = LogType.BATCH_DELETE)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/deleteBatch",method=RequestMethod.POST)
    @ResponseBody
    public R deleteByIds(@RequestBody int []ids){
        return iPatientService.deleteByIds(ids);
    }

    @OperLog(operation = "患者管理",type = LogType.UPDATE)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/edit",method=RequestMethod.POST)
    @ResponseBody
    public R edit(@RequestBody Patient patient) {
    return iPatientService.edit(patient);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/pay",method=RequestMethod.POST)
    @ResponseBody
    public R pay(@RequestBody PaymentDTO paymentDTO){
        return iPatientService.pay(paymentDTO);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/notify",method=RequestMethod.POST)
    @ResponseBody
    public String payNotify(HttpServletRequest request) throws AlipayApiException {
        return iPatientService.payNotify(request);
    }
}
